package com.eshealthy.controller;

import com.eshealthy.dao.ManagerDao;
import com.eshealthy.entity.Department;
import com.eshealthy.entity.Doctor;
import com.eshealthy.entity.Patient;
import com.eshealthy.service.ManagerService;
import com.eshealthy.serviceImpl.ManagerServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("manager")
@Slf4j
public class ManagerController {
    @Autowired
    private ManagerService managerService;
    /*
     * 查询所有医生信息
     * */

    @GetMapping("findAllDoctor")
    public Map<String,Object> findAll(Integer page,Integer rows,Integer id) {
        log.info("管理员id"+id);
        page = page==null?1:page;
        rows = rows==null?4:rows;
        HashMap<String,Object> map=new HashMap<>();
//        Integer.parseInt(id)
        List<Doctor> doctors= managerService.findAllDoctor(page, rows,id);
        Integer totals=managerService.findTotalsDoctor(id);
        Integer totalsPage=totals%rows==0?totals/rows:totals/rows+1;
        map.put("doctors",doctors);
        map.put("totals",totals);
        map.put("totalPage",totalsPage);
        map.put("page",page);
        return map;
    }
    /*
     * 查询所有科室信息
     * */
    @GetMapping("findAllDepartment")
    public Map<String,Object> findAllDepartment(Integer page,Integer rows,Integer id) {
        page = page==null?1:page;
        rows = rows==null?4:rows;
        HashMap<String,Object> map=new HashMap<>();
        List<Department> departments= managerService.findAllDepartment(page, rows,id);
        Integer totals=managerService.findTotalsDepartment(id);
        Integer totalsPage=totals%rows==0?totals/rows:totals/rows+1;
        map.put("departments",departments);
        map.put("totals",totals);
        map.put("totalPage",totalsPage);
        map.put("page",page);
        return map;
    }
}
